class Node:
    def __init__(self, data):
        # 初始化节点类，包含节点数据和下一节点的指针
        self.data = data  # 数据
        self.next = None  # 指针


class LinkList:
    def __init__(self):
        self.head = Node(None)

    def create(self, a):
        tail = self.head
        for i in range(len(a)):
            p = Node(a[i])
            tail.next = p
            tail = p

    def output(self):
        p = self.head.next
        while p != None:
            print(p.data, end=' ')
            p = p.next
        print()

# 查找相同链表元素，删除相同的元素
def deleteSame(ha):
    global n
    # 全局定义链表长度n
    n = 10
    print (n)
    p = ha.head.next
    while p != None:
        q = p
        r = p.next
        while r != None:
            if p.data == r.data:
                q.next = r.next
                n = n-1
                r = r.next
            else:
                q = r
                r = r.next
        p = p.next

try:    #尝试代码块，如遇error，忽略
    h = LinkList()
    h.create([21,30,14,55,32,63,11,30,55,30])
    h.output()
    deleteSame(h)
    print(n)
    h.output()
except EOFError:pass

